package org.mipt.infsec.steganography.impl.petzib.keys;

import org.mipt.infsec.steganography.api.datastorage.keys.Key;
import org.mipt.infsec.steganography.api.datastorage.keys.KeyGenerator;
import org.mipt.infsec.steganography.impl.petzib.datastorage.*;
import org.mipt.infsec.steganography.impl.petzib.datastorage.String;

import java.util.ArrayList;

public class KeyGeneratorImpl extends KeyGenerator<Integer>
{
    public static KeyGenerator getInstance()
    {
        if (keyGenerator == null) keyGenerator = new KeyGeneratorImpl();
        return keyGenerator;
    }

    @Override
    public Key<Integer>[] generateKeys(int number)
    {
        KeyImpl[] keys = new KeyImpl[number];
        for (int i = 0; i < number; i++)
        {
            keys[i] = new KeyImpl();
            if (i % 3 == 2) keys[i].setValue(41);
            if (i % 3 == 1) keys[i].setValue(53);
            if (i % 3 == 0) keys[i].setValue(31);
        }
        return keys;
    }

    /**
     * This method transform data string with
     * @param data
     * @return
     */
    public KeyImpl[] seek(java.lang.String data)
    {
        java.lang.String[] strings = data.split(" ");
        KeyImpl[] keys = new KeyImpl[strings.length];
        for (int i = 0; i < keys.length; i++)
        {
            keys[i] = new KeyImpl();
            keys[i].seekKey(new String(strings[i]));
        }
        return keys;
    }
}
